function stopPropagation(e) {//阻止事件冒泡方法
    e = e || window.event;  
    if(e.stopPropagation) { //W3C阻止冒泡方法  
        e.stopPropagation(); 
    } else {  
        e.cancelBubble = true; //IE阻止冒泡方法 
    }  
}
//关闭下载app悬浮模块
$("#close").on("click",function(e){       
    $("#download-app").hide();
    $("#footer").css("marginBottom","0");
    stopPropagation(e);
});

//滚动页面，当页面でscrollTop大于一定的值时显示回到顶部
$(window).scroll(function(){
    var height=$(window).height()*2;
    if($(window).scrollTop()>height){
        $("#back-top").show();
    }else{
        $("#back-top").hide();
    }
});
//点击回到顶部
$("#back-top").on("click",function(){
    $(this).hide();
    $(window).scrollTop(0);
});
var doc=document;
        // 获取终端的相关信息
var Terminal = {
    // 辨别移动终端类型
    platform : function(){
        var u = navigator.userAgent, app = navigator.appVersion;
        return {
            // android终端或者uc浏览器
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
            // 是否为iPhone或者QQHD浏览器
            iPhone: u.indexOf('iPhone') > -1 ,
            // 是否iPad
            iPad: u.indexOf('iPad') > -1
        };
    }(),
    isWeixin:function(){
        //判断是否为微信
        var ismicr;
        if(Terminal.platform.android){
            ismicr = (navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger");
        }else if(Terminal.platform.iPhone){
            ismicr=(navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger")|| navigator.userAgent.match(/qq/i) == "qq";
        }else{
            ismicr=false;
        }
        return ismicr;
    },
    // 辨别移动终端的语言：zh-cn、en-us、ko-kr、ja-jp...
    language : (navigator.browserLanguage || navigator.language).toLowerCase()
};
        
function showOrhide(){
    var linkUrl=download.androidUrl;
    if(Terminal.platform.android){
        location.href=linkUrl;
    }else if(Terminal.platform.iPhone){
        promptInfo();
//        location.href=download.iosUrl;
    }else if(Terminal.platform.iPad){
//        location.href=download.iosUrl;
        promptInfo();
    }else{
        location.href=linkUrl;
    }
} 

// 根据不同的终端，跳转到不同的地址
$("#down-content").on("click",function(){
    showOrhide();
});

function promptInfo(){
    if (Terminal.isWeixin()){ //下如果是微信浏览器,提示在浏览器中打开 
       $(".indicator").find(".img2").css("display","block")
                      .siblings().css("display","none");
       $(".loading-indicator").css("display","block");
       var newUrl=location.href+"&flags=yes";
       location.href=newUrl;
    } else { //不是微信浏览器的时候所做的判断
       $(".indicator").find(".img2").css("display","none")
                      .siblings().css("display","none");
       $(".loading-indicator").css("display","none");
       location.href=download.iosUrl;
    }
}
    //判断是否登录
    var haslogin=localStorage.haslogin;
    var userId=localStorage.userId;
    console.log(haslogin);
    var userIdStr="";
    if(haslogin){
        if(userId!=""&&userId!=undefined){
            userIdStr='?userId='+userId;    
        }else{
            userIdStr='';
        }
    }
    console.log(haslogin+"--"+userId);
    //点击我的或者登陆按钮，跳转到登录或者是我的信息页面
    $(".login").on("click",function(){
        if(window.localStorage){
            if(haslogin!=undefined){
                if(haslogin=="true"){
                    //跳转到我的信息页面
                    location.href="./myself.html"+userIdStr;
                }else{
                    //跳转到登录页面
                   location.href="./login.html";
                }    
            }else{
                location.href="./login.html";
            }
        }else{
            alert("请打开浏览器cookie功能");
            console.log("浏览器不支持localstorage");
        }
    });
    //返回上一页
    $(".search-left,.header-left,.back-img").on("click",function(){
        history.back(-1);  
    });